<%--
  Created by IntelliJ IDEA.
  User: liuxi
  Date: 2018/6/5
  Time: 19:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/bootstrap/css/bootstrap.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/table/bootstrap-table.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/date/bootstrap-datetimepicker.min.css"/>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/statics/sweetalert.css"/>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/sweetalert.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/jquery-3.2.1.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/table/bootstrap-table.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/date/Moment.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/date/bootstrap-datetimepicker.min.js"></script>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-body">
        <form class="form-inline">
            <div class="form-group">
                名字：<input id="nName" name="nName" type="text" class="form-control" placeholder="搜索内容">
            </div>
            <div class="form-group">
                手机号：<input id="nCall" name="nCall" type="text" class="form-control" placeholder="搜索内容">
            </div>
            性别：<select id="nSex" class="form-control">
                <option value="全部">全部</option>
                <option value="男">男</option>
                <option value="女">女</option>
            </select>
            入职时间:
            <div class="input-group input-daterange">
                <input id="nEntryDate" type="text" class="form-control">
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
            <button onclick="search()" type="button" class="btn btn-default">查询</button>
        </form>
    </div>
</div>
<table id="table"></table>
</body>

<script type="text/javascript">




    function search() {
        var opts = $("#table").bootstrapTable('getOptions');
        var nName = $("#nName").val();
        var nCall = $("#nCall").val();
        var nSex = $("#nSex").val();
        var nEntryDate = $("#nEntryDate").val();
        $.ajax({
            "url": "${pageContext.request.contextPath}/Nurse/query",
            "type": "post",
            "data": {
                "nCall": nCall,
                "nSex": nSex,
                'nName': nName,
                "nEntryDate":nEntryDate,
                "pageNumber": opts.pageNumber,
                "pageSize": opts.pageSize

            },
            "dataType": "json",
            "success": function (data) {
                $("#table").bootstrapTable('load', data);
            }
        })
    }



    window.operateEvents = {
        "click .del": function (e, value, row, index) {
            swal({
                title: "您确定要删除这条信息吗",
                text: "删除后将无法恢复，请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "删除",
                closeOnConfirm: true
            }, function () {
                $.ajax({
                    "url": '${pageContext.request.contextPath}/Nurse/del',
                    "type": "post",
                    "data": {"nId": row.nId},
                    "dataType": "json",
                    "success": function (data) {
                        if (data >= 1) {
                            $("#table").bootstrapTable("refresh");
                        }
                    }
                })
            });
        }
    };



    $(function () {




        // 时间插件
        $('#nEntryDate').datetimepicker({
            //viewMode: 'day',
            format: 'YYYY-MM-DD'
        });





        function queryParams(params) {
            var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                pageSize: params.pageSize,  //页面大小
                pageNumber: params.pageNumber, //页码
                nName: $("#nName").val(),
                nCall: $("#nCall").val(),
                nSex:$("#nSex").val(),
                nEntryDate:$("#nEntryDate").val()
            };
            return temp;
        }
        //bootstrapTable
        $("#table").bootstrapTable({
            url: '${pageContext.request.contextPath}/Nurse/query',
            columns: [{
                field: 'nImg',
                title: '头像',
                formatter:function (value,row,index) {
                    return "<img  style='width: 67px;height: 39px;' src='${pageContext.request.contextPath}"+row.nImg+"'    />";
                }
            },{
                field: 'nId',
                title: '职员编号'
            }, {
                field: 'nName',
                title: '职员名字'
            }, {
                field: 'nCards',
                title: '身份证号'
            }, {
                field: 'nSex',
                title: '性别'
            }, {
                field: 'nCall',
                title: '手机号'
            }, {
                field: 'nEmal',
                title: '邮箱'
            }, {
                title: '职位',
                formatter:function(index, row, value){
                    if(row.posId==1){
                        return "护士";
                    }else if(row.posId==2){
                        return "医生";
                    }else if(row.posId==3){
                        return "主任"
                    }else if(row.posId==4){
                        return "药房人员";
                    }else if(row.posId==5){
                        return "医技医生";
                    }else if(row.posId==6){
                        return "管理员";
                    }
                }
            }, {
                field: 'nBirthDate',
                title: '生日'
            }, {
                field: 'nEntryDate',
                title: '入职时间'
            }, {
                title: '是否在职',
                formatter:function(index, row, value){
                    if(row.nEntryIsTrue==0){
                        return "在职";
                    }else if(row.nEntryIsTrue==1){
                        return "不在职";
                    }
                }
            }, {
                field: 'nSalary',
                title: '工资'
            }, {
                title: '操作',
                events: operateEvents,
                formatter: caozuo
            }],
            method: 'post',
            contentType: "application/x-www-form-urlencoded",
            height: 500,
            pageList: [5, 10, 15],
            pageSize: 5,
            sortable: true,
            sortOrder: "asc",
            pageNumber: 1,
            pagination: true,
            queryParamsType: '',
            queryParams: queryParams,
            sidePagination: 'server'
        });
        function caozuo(value, row, index) {
            return [
                "<a class='del' href=javascript:del(" + row.nId + ")>删除</a>"
            ].join("");
        }

    });
</script>
</html>
